package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-05-18
 * Time: 15:38
 */
class Person{
    //普通成员变量
    public String name;
    public int age;
    //构造方法
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("父类的带两个参数的构造方法");
    }
    //实例代码块
    {
        this.name = "小明";
        this.age = 15;
        System.out.println("父类的实例化代码块");
    }
    //静态代码块
    static {
        System.out.println("父类的静态代码块");
    }
    public Person(){
        System.out.println("父类的构造方法");
    }
}
class Student extends Person{
    //静态成员变量
    public static String classRoom;

    //实例代码块,用于初始化普通成员变量
    {
        this.name = "小张";
        this.age = 18;
        System.out.println("子类的实例化代码块");
    }
    //静态代码块，用于初始化静态成员变量
    static {
        //this.classRoom;//error static修饰的成员变量不能使用this
        classRoom = "111";
        System.out.println("子类的静态代码块");
    }
    //普通成员方法
    public void show(){
        System.out.println("姓名："+this.name+"\n年龄："+this.age);
    }
    //构造方法
    public Student(){
        //super() //默认存在，用于调用父类的构造方法
        System.out.println("子类的构造方法");
    }
}
public class Test02 {
    public static void main(String[] args) {
        Student stu = new Student();
        stu.show();
        System.out.println("==========");
        Student stu2 = new Student();
        stu2.show();
    }
}
